new Vue({
  el: "#app",
  data() {
    return {
      BASE_IMG: "https://www.kdddy.cn/Image/",
      headData: [
        {
          type: "index",
          label: "序号",
          width: "50",
          align: "center",
        },
        {
          label: "专家姓名",
          prop: "Expert_Name",
          align: "center",
        },
        {
          label: "照片",
          width: "140",
          align: "center",
          image: {
            type: "url",
            base: Domain_Business,
            style: "width: 100px; height: 100px; border-radius: 5px;",
            value: "Picture_URL",
            error: absolutepath() + "admin/icons/NoLogo.png",
          },
        },
        {
          label: "详细地址",
          align: "center",
          slot: [
            {
              type: "key",
              value: "Province",
            },
            {
              type: "key",
              value: "City",
            },
            {
              type: "key",
              value: "County",
            },
            {
              type: "key",
              value: "Address",
            },
          ],
        },
        {
          label: "职业",
          prop: "Expert_Type_Name",
          align: "center",
        },
        {
          label: "擅长领域",
          prop: "Category_Name",
          align: "center",
        },
        {
          label: "咨询量",
          align: "center",
          slot: [
            {
              type: "key",
              value: "Consult_Total",
            },
          ],
        },
        {
          label: "回复总量",
          align: "center",
          slot: [
            {
              type: "key",
              value: "Reply_total1",
            },
          ],
        },
        {
          label: "状态",
          width: "100",
          align: "center",
          tag: [
            {
              type: (row) => {
                return row.Row_Status == "1"
                  ? "success"
                  : row.Row_Status == "2"
                  ? "danger"
                  : "";
              },
              value: (row) => {
                return row.Row_Status == "1"
                  ? "已通过"
                  : row.Row_Status == "2"
                  ? "已拒绝"
                  : "待审核";
              },
            },
          ],
        },
      ],
      form: {
        SQLSerialNumber: "P_business_expert_1",
        PaginationNumber: 1, //页数
        RowAmount: 10, //每页数据条数
        Expert_Name: "",
        Row_Status: "-",
        Condition: "",
        ExtensionCondition: "",
      },
      total: 0,
      tableData: [], //表格数据
      ExportData: [], //导出
      defaultProps: {
        children: "Children",
        label: "label",
      },
      loading: false,
      dialogVisible: false,
      isTree: true,
    };
  },
  mounted() {
    this.getList(this.form); //前端分页
  },
  methods: {
    onSerach() {
      //查询方法
      this.form.PaginationNumber = 1;
      this.getList(this.form);
    },
    handleSizeChange(val) {
      this.form.PaginationNumber = 1;
      this.form.RowAmount = val;
      this.getList(this.form);
    },
    handleCurrentChange(val) {
      this.form.PaginationNumber = val;
      this.getList(this.form);
    },
    getList(form) {
      //换页方法
      const that = this;
      let data = deepClone(form);
      data.Condition = window.btoa(
        unescape(encodeURIComponent("%" + data.Expert_Name + "%"))
      );
      if (data.Row_Status != "-") {
        data.ExtensionCondition = window.btoa(
          unescape(
            encodeURIComponent(
              " AND business_expert.Row_Status = '" + data.Row_Status + "'"
            )
          )
        );
      }
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        type: "POST",
        data,
        success: function (Result) {
          console.log(Result);

          that.tableData = Result.Rows;
          that.total = Result.TotalRows;
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    handleOperate(command, row) {
      if (command == "approve") {
        this.Remove(row, "1");
      } else if (command == "refuse") {
        this.Remove(row, "2");
      } else if (command == "approve2") {
        this.Remove(row, "0");
      } else if (command == "edit") {
        this.Edit(row);
      } else if (command == "remove") {
        this.Remove(row, "3");
      } else if (command == "Qr") {
        this.dialogVisible = true;
        // console.log(
        //   "https://marketing.xiaokanglongjiang.com/dist/System/view/expertconsult/expertconsult/edit.html?Expert_SerialNumber=" +
        //     row.Expert_SerialNumber +
        //     "&type=1"
        // );
        this.$nextTick(() => {
          $("#qrcode-container").qrcode({
            width: 160, // 二维码宽度（单位像素）
            height: 160, // 二维码高度（单位像素）
            text:
              "https://www.kdddy.cn/manage/view/expertconsult/expertconsult/edit.html?Expert_SerialNumber=" +
              row.Expert_SerialNumber +
              "&type=1", // 二维码包含的内容
          });
        });
      }
    },
    Add() {
      window.location.href = "./add.html";
    },
    Edit(row) {
      sessionStorage.setItem("Expert_SerialNumber", row.Expert_SerialNumber);
      window.location.href =
        "./edit.html?Expert_SerialNumber=" + row.Expert_SerialNumber;
    },
    Remove(data, Row_Status) {
      const that = this;
      let label =
        Row_Status == "0"
          ? "重新审核"
          : Row_Status == "1"
          ? "通过"
          : Row_Status == "2"
          ? "拒绝"
          : "删除";
      this.$confirm("此操作将" + label + "该专家信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let row = deepClone(data);
          row.Row_Status = Row_Status;
          $.ajax({
            headers: requestHeaders(),
            url: `${BASE_URL2}/generalBusiness/generalSave`,
            type: "POST",
            data: {
              Data: JSON.stringify({
                Modify: { business_expert: [row] },
              }),
            },
            success: function (res) {
              if (res.Status === "success") {
                that.$message({
                  type: "success",
                  message: label + "成功!",
                });
              } else {
                that.$message.error(label + "失败，请稍后再试");
              }
              that.getList(that.form);
            },
            complete: function (XMLHttpRequest) {
              that.loading = false;
              requestPretreatment(XMLHttpRequest);
            },
            dataType: "json",
          });
        })
        .catch(() => {});
    },
  },
});
